package pluginUtils;

public class limCircle implements Comparable{
	
	private double radius;
	private limComplexe center;
	/**
	 * @return the radius
	 */
	public double getRadius() {
		return radius;
	}
	/**
	 * @param radius the radius to set
	 */
	public void setRadius(double radius) {
		this.radius = radius;
	}
	/**
	 * @return the center
	 */
	public limComplexe getCenter() {
		return center;
	}
	/**
	 * @param center the center to set
	 */
	public void setCenter(limComplexe center) {
		this.center = center;
	}
	/**
	 * @param radius
	 * @param center
	 */
	public limCircle(double radius, limComplexe center) {
		super();
		this.radius = radius;
		this.center = center;
	} 
	
	public limCircle(limComplexe center,double radius) {
		super();
		this.radius = radius;
		this.center = center;
	}
	
	private double slope(double x){
		double xx=x+Math.PI; 
		while(xx<0) xx=xx+1.0; 
		while(xx>=1.0) xx=xx-1.0; 
		return xx; 
	}
	
	
	@Override
	public int compareTo(Object o) {
		
		limCircle lco=(limCircle)o; 
		if((this.getRadius()<=0)&&(lco.getRadius()>0)) return -1; 
		if((this.getRadius()>0)&&(lco.getRadius()<=0)) return 1; 
		double small=limConstants.EPS/limConstants.AGREE;
		double dx=this.getCenter().getReal()-lco.getCenter().getReal(); 
		if(dx<-small) return -1; 
		if(dx>small) return 1; 
		
		double dy=this.getCenter().getIm()-lco.getCenter().getIm(); 
		if(dy<-small) return -1; 
		if(dy>small) return 1;
		if(this.getRadius()<=0){
			double dr=slope(this.getRadius())-slope(lco.getRadius());
			if(dr<-limConstants.PARAFUZZ) return -1; 
			if(dr>limConstants.PARAFUZZ) return 1;
			return 0; 
		}
		double dr=this.getRadius()-lco.getRadius(); 
		if(dr<-small) return  -1;
		if(dr>small) return 1; 
		return 0; 
	} 
	
	public int hashCode(){return 1; }
	
	public boolean equals(Object o){
		if(!(o instanceof limCircle)) return false; 
		return (this.compareTo(o)==0); 
	}
	
	public String toString(){
			return this.center+" "+this.radius; 
	}

}
